# 导包
from api.login import LoginAPI
from api.course import CourseAPI


# 创建测试类
class TestCourseAPI:
    token = None

    # 前置条件
    def setup(self):
        self.login_api = LoginAPI()
        self.course_api = CourseAPI()
        # 登录成功
        # 获取验证码
        res_v = self.login_api.get_verify_code()
        # 登录
        login_data = {
            "username": "admin",
            "password": "HM_2023_test",
            "code": "2",
            "uuid": res_v.json().get("uuid")
        }
        res_l = self.login_api.login(test_data=login_data)
        # 提取登录成功的token
        TestCourseAPI.token = res_l.json().get("token")
        print(TestCourseAPI.token)

    # 后置条件
    def teardown(self):
        pass

    # 课程修改成功 1000132075
    def test01_delete_success(self):
        response = self.course_api.delete_course(course_id=1000132451, token=TestCourseAPI.token)
        print(response.json())
        assert 200 == response.status_code
        assert "成功" in response.text
        assert 200 == response.json().get('code')

    # 课程修改失败
    def test02_delete_fail(self):
        response = self.course_api.delete_course(course_id=666, token=TestCourseAPI.token)
        print(response.json())
        assert 200 == response.status_code
        assert "失败" in response.text
        assert 500 == response.json().get('code')

    def test03_delete_fail(self):
        response = self.course_api.delete_course(course_id=666, token="xxx")
        print(response.json())
        assert 200 == response.status_code
        assert "失败" in response.text
        assert 401 == response.json().get('code')

